--display:create ( "Device Enumeration", 640, 480, 32, true )

local dm = DisplayMode ( )
dm.width = 640
dm.height = 480
dm.depth = 32
dm.windowed = true
display:set_mode ( dm )

devices = system.enumerate_devices ( system.DEV_CLASS_ALL )

local font = Font ( )
font:load_system  ( "Courier", 16 )

local sprite = Sprite ( )
sprite.canvas:set_font ( font, YELLOW )
display.viewport:add_child ( sprite )

local file = "devices.txt"
local output = io.open ( file, "w" )

sprite.canvas:move_to ( -320 + 4, 240 - 16 )
sprite.canvas:write ( "List of devices logged to: " .. file )

for i, device in ipairs ( devices ) do
	local out = string.format ( "%d. %s\n", i, device )

	-- output to log file
	output:write ( out )

	-- output to screen
	sprite.canvas:move_to ( -320 + 4, 240 - 16 * ( i + 2 ) )
	sprite.canvas:write ( out )
end

output:close ( )